package com.heima.wemedia.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.ChannelDto;
import com.heima.model.wemedia.pojo.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "自媒体频道管理", tags = "自媒体频道管理")
public class WmChannelController {
    /**
     * 服务对象
     */
    @Resource
    private WmChannelService wmChannelService;

    @GetMapping(path = "/channels")
    @ApiOperation("自媒体频道列表查询")
    public ResponseResult<List<WmChannel>> channels() {
        List<WmChannel> channelList = wmChannelService.channels();
        return ResponseResult.success(channelList);
    }

    @PostMapping("/list")
    @ApiOperation("自媒体频道列表查询")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        IPage page = wmChannelService.findByNameAndPage(dto);
        return PageResponseResult.success(page);
    }

    @PostMapping("/save")
    @ApiOperation("新增频道")
    public ResponseResult insert(@RequestBody WmChannel adChannel) {
        wmChannelService.insert(adChannel);
        return ResponseResult.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改频道")
    public ResponseResult update(@RequestBody WmChannel adChannel) {
        wmChannelService.update(adChannel);
        return ResponseResult.success();
    }

    @GetMapping("/del/{id}")
    @ApiOperation("删除频道")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        wmChannelService.delete(id);
        return ResponseResult.success();
    }

}

